#include "Frog.h"
#include "EcoSystem.h"
#include "Environment.h"
Frog::Frog(EcoSystem *eco_system) :
Consumer(eco_system)
{
    set_alive();
    set_max_hp(7000);
    set_hp(get_max_hp() / 2);
    set_init_speed(8.0);
    set_speed(get_init_speed());
    set_life_span(LIFE_SPAN[get_species_id()] * (1 + max(min(0.2, EcoSystem::random_double() - 0.5), -0.2)));
}

Frog::~Frog() {}

const unsigned int Frog::get_species_id() const
{
    return FROG_SPECIES_ID;
}

Gdiplus::Image *Frog::get_entity_image() const
{
    static Gdiplus::Image *img = Gdiplus::Image::FromFile(L".\\images\\frog.png");
    static Gdiplus::Image *img_s = Gdiplus::Image::FromFile(L".\\images\\frog_s.png");
    
    if (is_sleep)
        return img_s;
    return img;

}

Entity *Frog::new_entity() const
{
    return new Frog(eco_system);
}
void Frog::on_tick()
{
    Environment *ptr = eco_system->get_environment_instance();
    if (ptr->get_temperature() > 30.0 || ptr->get_temperature() < 5.0){
        set_hp(get_hp()*0.8);
    }

    if (ptr->get_season() == 3){// while winter , sleep, and age doesn't increase
        set_init_speed(0.0);
        is_sleep = true;
    }
    else{ 
        set_init_speed(8.0);
        is_sleep = false;
        set_age(get_age() + 1);

        if (get_age() > get_life_span())
            set_dead();

        set_hp(get_hp() - get_speed());
        multiply();

        if (!avoid_predator(get_init_speed()*1.5))
        if (!prey(get_init_speed()))
            random_motion(get_init_speed()*0.3);

    }

}

int    Frog::get_cost_of_being_preyed() const
{
    return get_hp() * 0.15;
}

int    Frog::get_gain_after_being_preyed() const
{
    return get_hp() * 0.2;
}